import { Wallet as EthersWallet } from "@ethersproject/wallet";
import { Wallet as XrplWallet, xrpToDrops as XrplXrpToDrops } from "xrpl";
import { evmAddressToXrplAccount, xrplAccountToEvmAddress } from "../util/address-derivation";

export const sleep = (s: number): Promise<void> => new Promise((resolve) => setTimeout(resolve, s * 1000));

export function claimIDToHex(claimID: number): string {
    return claimID.toString(16).padStart(16, "0").toUpperCase();
}

export function claimIDToNum(claimID: string): number {
    return parseInt(claimID, 16);
}

export function evmPkToXrpAddress(pk: string): string {
    const wallet = new EthersWallet(pk);
    return evmAddressToXrplAccount(wallet.address);
}
export function xrpPkToEvmAddress(pk: string): string {
    const wallet = XrplWallet.fromSeed(pk);
    return xrplAccountToEvmAddress(wallet.address);
}

export function xrpToDrops(amount: number): string {
    const normalized = Math.floor(amount * 1_000_000) / 1_000_000;
    return XrplXrpToDrops(normalized);
}
